/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __LOGFILE_H__
#define __LOGFILE_H__

#pragma once

#include <string>
#include <iostream>
#include <fstream>
#include <sstream>

#include "common/Singleton.h"

/**
 * \ingroup CoreEngine
 *
 * The Log class.<br>
 * A Message Logger. Writes output to a file.<br>
 * Use this like:
 * <code>coreGetLog()->WriteLog("My Error", __FILE__, __LINE__);</code>
 *
 * \date 03-28-2007
 *
 * \author juckel
 *
 */
class DLL_EXPORT Log
//	: public Singleton<Log>
{
public:
	void Delete();

	/// Clears the log file
	void ClearLog(const std::string &fileName);

	/// Write a normal message to the log. The application can continue normally with full functionality.
	void WriteLog(const std::string &errorReport, const std::string &fileName = "", int lineNumber = 0);

	/// Write a warning to the log. The application can continue, but with missing features.
	void WriteWarning(const std::string &errorReport, const std::string &fileName = "", int lineNumber = 0);

	/// Write a fatal error to the log. The application cannot continue and must exit.
	void WriteError(const std::string &errorReport, const std::string &fileName = "", int lineNumber = 0);

	/// Write a error while using Lua.
	void WriteLuaError(const std::string &errorReport, const std::string &fileName = "", int lineNumber = 0);

	/// Returns the filename of the log file
	const std::string& getFilename() const;

	void setStringStream(std::stringstream *stream);

	Log(const std::string &filename);
	virtual ~Log(void);

private:
	std::string sFileName;
	std::ofstream ofstr;
	std::stringstream *strStream;
};


/**
 * Returns the core's instance of the Log object
 */
DLL_EXPORT
Log* coreGetLog();

DLL_EXPORT
bool coreInitLog(const std::string &filename);

#endif
